package org.dochandler.esfinge.guardian.authorizer;

import org.dochandler.service.MissionReportService;
import org.dochandler.service.domain.Officer;
import org.dochandler.service.domain.annotation.AllowInMissionLocationOnly;
import org.dochandler.service.domain.constants.Constants;
import org.dochandler.service.domain.mission.Mission;
import org.dochandler.service.util.ServiceLocator;
import org.esfinge.guardian.authorizer.Authorizer;
import org.esfinge.guardian.context.AuthorizationContext;

public class AllowInMissionLocationOnlyAuthorizer implements Authorizer<AllowInMissionLocationOnly> {

	@Override
	public Boolean authorize(AuthorizationContext context, AllowInMissionLocationOnly securityAnnotation) {
		
		Officer officer = context.getSubject().get( Constants.OFFICER.val(), Officer.class );
		Mission mission = context.getResource().get( Constants.MISSION.val(), Mission.class );
		
		MissionReportService mrs = ServiceLocator.getServiceImplementation(MissionReportService.class);
		return mrs.isOfficerInTheMissionLocation(officer, mission);
		
	}

}